// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: wsfuyibing <682805@qq.com>
// Date: 2024-11-19

package common

import (
	"context"
	"time"
)

type (
	Span interface {
		Child(format string, args ...any) Span
		End()
		Release()

		SpanWithGetter
		SpanWithLogger
	}

	SpanFormatter interface {
		ToByte(span Span) []byte
		ToString(span Span) string
	}

	SpanManager interface {
		GetPlugin() (plugin SpanPlugin)
		Send(span Span)
		SetPlugin(plugin SpanPlugin)
		Wait()
	}

	SpanPlugin interface {
		GetFormatter() (formatter SpanFormatter)
		GetReporter() (reporter SpanReporter)
		Report(spans []Span) (err error)
		SetFormatter(formatter SpanFormatter)
		SetReporter(reporter SpanReporter)
	}

	// SpanReporter
	// 上报跟踪数据, 应用于 Jaeger, Zipkin 等.
	SpanReporter interface {
		// Report
		// 上报数据.
		Report(formatter SpanFormatter, spans []Span) (err error)
	}

	// SpanWithGetter
	// 读取参数.
	SpanWithGetter interface {
		GetAttr() Attr
		GetContext() context.Context
		GetEndTime() time.Time
		GetDuration() time.Duration
		GetLogs() []Item
		GetName() string
		GetStartTime() time.Time
		GetTracing() Tracing
	}

	// SpanWithLogger
	// 操作日志.
	SpanWithLogger interface {
		Debug(format string, args ...any)
		Info(format string, args ...any)
		Warn(format string, args ...any)
		Error(format string, args ...any)
		Fatal(format string, args ...any)
	}
)
